﻿/*
 * 文件名称：
 * 程序员：wangyun
 * 创建时间：2008/6/2
 * 
 * 功能说明：信息来源的添加或修改页面
 * 
 * 修改人员：
 * 
 * 修改日期：
 * 
 * 修改记录：
 */

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Whir.Common.WebHelper;

public partial class Whir_System_Module_Config_Source : System.Web.UI.Page
{
    protected string action = "";
    protected int infoID = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        RoleHelper.IsLogin();    //登录判断

        action = NetRequest.GetQueryString("Action");
        infoID = NetRequest.GetQueryInt("InfoID");

        if (!IsPostBack)
        {
            switch (action)
            {
                case "Add": break;
                case "Modify":
                    BindData();
                    Button1.Text = "更新";
                    break;
                case "Delete":
                    BindData();
                    Button1.Text = "删除";
                    this.Button1.Attributes.Add("onclick", "return confirm('确定要删除吗？');");
                    break;
            }
        }
    }

    private void BindData()
    {
        Whir.BLL.Whir_Source bll = new Whir.BLL.Whir_Source();
        Whir.Model.Whir_Source model = bll.GetModel(infoID);

        txtInfoTitle.Text = model.infoTitle;
        txtInfoDesc.Text = model.infoDesc;
        txtInfoComeFrom.Text = model.infoComeFrom;
        txtInfoContact.Text = model.infoContact;
        txtInfoPhone.Text = model.infoPhone;
        txtInfoAddress.Text = model.infoAddress;
        txtInfoFax.Text = model.infoFax;
        txtInfoOther.Text = model.infoOther;
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Whir.BLL.Whir_Source bll = new Whir.BLL.Whir_Source();
        Whir.Model.Whir_Source model;

        switch (action)
        {
            case "Add":
                model = new Whir.Model.Whir_Source();
                model.infoTitle = txtInfoTitle.Text.Trim();
                model.infoDesc = txtInfoDesc.Text.Trim();
                model.infoComeFrom = txtInfoComeFrom.Text.Trim();
                model.infoContact = txtInfoContact.Text.Trim();
                model.infoPhone = txtInfoPhone.Text.Trim();
                model.infoAddress = txtInfoAddress.Text.Trim();
                model.infoFax = txtInfoFax.Text.Trim();
                model.infoOther = txtInfoOther.Text.Trim();
                model.CreateUserID = 0;

                bll.Add(model);
                break;
            case "Modify":
                model = bll.GetModel(infoID);
                model.infoTitle = txtInfoTitle.Text.Trim();
                model.infoDesc = txtInfoDesc.Text.Trim();
                model.infoComeFrom = txtInfoComeFrom.Text.Trim();
                model.infoContact = txtInfoContact.Text.Trim();
                model.infoPhone = txtInfoPhone.Text.Trim();
                model.infoAddress = txtInfoAddress.Text.Trim();
                model.infoFax = txtInfoFax.Text.Trim();
                model.infoOther = txtInfoOther.Text.Trim();
                model.CreateUserID = 0;

                bll.Update(model);
                break;

            case "Delete":
                model = bll.GetModel(infoID);
                if (model != null)
                {
                    bll.Delete(infoID);
                }
                break;
        }

        Response.Redirect("SourceManage.aspx");
    }
}
